<?
/**
 *后端向前端返回的消息结构
 *以json的格式返回
 */

class Msg
{
	//消息说明
	private $_desc;
	
	//消息返回code
	private $_return_code;
	
	//消息数据域
	private $_data;
	
	//构造函数
	public function __construct()
	{
		$num = func_num_args();
		$param = func_get_args();
		switch($num)
		{
			case 0:
				$this->_construct0();
				break;
			case 3:
				$this->_construct3();
				break;
		}
	}
	
	/**
	 *构造函数1
	 */
 	private function _construct0()
	{
	}
	
	/**
	 *构造函数2
	 */
 	private function _construct3($desc, $return_code, $array)
	{
		$this->_desc = $desc;
		$this->_return_code = $return_code;
		$this->_data = $array;	
	}
	
	public function set($array)
	{
		if(isset($array['desc']))
			$this->_desc = $array['desc'];	
		if(isset($array['return_code']))
			$this->_return_code = $array['return_code'];
		if(isset($arrayp['data']))
			$this->_data = $array['data'];		
	}
	
	public function set_desc($desc)
	{
		$this->_desc = $desc;
	}
	
	public function set_return_code($return_code)
	{
		$this->_return_code = $return_code;
	}
	
	public function set_data($data)
	{
		$this->_data = $data;
	}
	
	public function get_msg()
	{
		$msg = array(
			'desc'=>$this->_desc,
			'return_code'=>$this->_return_code,
			'data'=>$this->_data
			);
		return $msg;
	}
	
	public function get_msg_json()
	{
		return json_encode($this->get_msg());
	}
	
	public function output_msg()
	{
		echo $this->get_msg_json();
	}
	
	public function __toString()
	{
		return $this->get_msg_json();
	}
}
?>